﻿using Yorrick.FlickrMetadataSynchr.Local;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace UnitTests
{
    /// <summary>
    ///This is a test class for GpsCoordinatesHelperTest and is intended
    ///to contain all GpsCoordinatesHelperTest Unit Tests
    ///</summary>
    [TestClass()]
    public class GpsCoordinatesHelperTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for EncodeExifCoordinate
        ///</summary>
        [TestMethod()]
        public void EncodeExifCoordinateTest()
        {
            //4°5'49.506" = 4.097085
            double coordinate = 4.097085F;
            ulong[] expected = 
            {
                // The first four bytes are the numerator, the second four bytes are the denominator
                // The first ulong is the number or degrees, the second the minutes, the third the seconds
                BitConverter.ToUInt64(new byte[] { 4, 0, 0, 0, 1, 0, 0, 0 }, 0),
                BitConverter.ToUInt64(new byte[] { 5, 0, 0, 0, 1, 0, 0, 0 }, 0),
                // The denominator for seconds is 1000000 = 0x000F4240
                // 0x02F366D0 = 49506000 = 49.506 * 1000000
                BitConverter.ToUInt64(new byte[] { 0xD0, 0x66, 0xF3, 0x02, 0x40, 0x42, 0x0F, 0x00 }, 0)
            };

            ulong[] actual;
            actual = GpsCoordinatesHelper.EncodeExifCoordinate(coordinate);
            Assert.AreEqual(expected[0], actual[0]);
            Assert.AreEqual(expected[1], actual[1]);
            Assert.AreEqual(expected[2], actual[2]);
        }
    }
}
